package com.frxuexi.shop2307

import android.util.Log

interface Meth{
    fun chong()
}

open class DianClass{
    open fun usb(){
        println("都有USB")
    }

//    abstract fun tong()
}

class Phone:DianClass(),Meth{
    override fun chong() {
        println("手机在充电")
    }

   /* override fun tong() {
        println("手机在通话")
    }*/


}

enum class Color{
    RED,BLUE,WHITE,GREEN
}

/*
fun main() {
            val phone = Phone()
        phone.chong()
        phone.usb()
//        phone.tong()

        Log.i("lr",Color.BLUE.toString())

        val array = arrayOf(1, 2, 3, 4, 5)
        for (i in 0..array.size-1){
            if(array[i]%2==0){
                Log.i("TAG", "onCreate: ${array[i]}")
            }
        }
        val list = mutableListOf<Int>(1, 2)
        list.add(0,3)
        Log.i("TAG", "onCreate: ${list.toString()}")

        Log.i("lr","12345".sum().toString())
        sum(3) { a, b ->
            return@sum a + b
        }
        /*sum(4,{a,b->
            return@sum a+b
        })*/

        myPrint {
            Log.i("lr","p函数")
        }

        fun2 {a->
            Log.i("lr","接收的值${a}")
        }

        fun3 {
            it.length
        }

        fun4()("张三")
//        res("张三")

        val result = fun5()("李四","男")
        Log.i("lr",result)

        val stu = Stu("王五", "男")
        with(stu){
            Log.i("lr",name)
            Log.i("lr",sex)
            study()

        }
        stu?.let {
            Log.i("lr",it.name)
            Log.i("lr",it.sex)
            it.study()
        }

        stu?.apply {
            Log.i("lr",name)
            Log.i("lr",sex)
            study()
        }

        stu.also {

        }

        GlobalScope.launch {
            flow<Int> {
                val list = listOf<Int>(1, 2, 3, 4, 5, 6)
                list.forEach {
                    Log.i("lr","flow:${it}")
                    delay(1000)
                    emit(it)
                }
            }.map { it*3 }.filter { it%2==0 }.buffer(100,BufferOverflow.DROP_OLDEST).flowOn(Dispatchers.IO).collect{
                Log.i("lr","收到flow:${it}")
            }

            /*(1..7).asFlow().collect{
                Log.i("lr","收到flow:${it}")
            }*/
        }

        val channel = Channel<Int>()

        GlobalScope.launch {
            channel.receiveAsFlow().collect{
                Log.i("lr",it.toString())
            }
        }

        GlobalScope.launch {
            channel.send(20)
        }

}
*/



class Stu(name:String,sex:String){
    var name:String=""
    var sex:String=""
    init {
        this.name=name
        this.sex=sex
    }
    fun study(){
        Log.i("lr","${name}在学习")
    }
}

fun myPrint(p:()->Unit){
    Log.i("lr","无参无返回值的匿名")
    p()
}

fun fun2(f:(Int)->Unit){
    f(3)
}

fun fun3(f:(String)->Int){
    val len = f("hello")
    Log.i("lr", "fun3: ${len}")
}

fun fun4():(String)->Unit{
    return {
        Log.i("lr","传的值是${it}")
    }
}

fun fun5():(String,String)->String{
    return {a,b->
        "传的值是${a},${b}"
    }
}

fun sum(int: Int,s:(Int,Int)->Int):Unit{
    val s1 = s(2, 3)
    Log.i("lr",s1.toString())
}

fun String.sum():Int{
    var s=0
    for (i in 0..length-1){
        s += this[i].toString().toInt()
    }
    return s
}